package com.ruoyi.web.controller.mall.goodsTypeParams.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.goodsTypeParams.domain.GoodsTypeParams;
import com.ruoyi.web.controller.mall.goodsTypeParams.service.IGoodsTypeParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类型参数名称Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/goodsTypeParams")
public class GoodsTypeParamsController extends BaseController
{
    private String prefix = "mall/goodsTypeParams";

    @Autowired
    private IGoodsTypeParamsService goodsTypeParamsService;

//    @RequiresPermissions("mall:goodsTypeParams:view")
    @GetMapping()
    public String goodsTypeParams()
    {
        return prefix + "/goodsTypeParams";
    }

    /**
     * 查询类型参数名称列表
     */
//    @RequiresPermissions("mall:goodsTypeParams:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsTypeParams goodsTypeParams)
    {
        startPage();
        List<GoodsTypeParams> list = goodsTypeParamsService.selectGoodsTypeParamsList(goodsTypeParams);
        return getDataTable(list);
    }

    /**
     * 导出类型参数名称列表
     */
//    @RequiresPermissions("mall:goodsTypeParams:export")
    @Log(title = "类型参数名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsTypeParams goodsTypeParams)
    {
        List<GoodsTypeParams> list = goodsTypeParamsService.selectGoodsTypeParamsList(goodsTypeParams);
        ExcelUtil<GoodsTypeParams> util = new ExcelUtil<GoodsTypeParams>(GoodsTypeParams.class);
        return util.exportExcel(list, "goodsTypeParams");
    }

    /**
     * 新增类型参数名称
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存类型参数名称
     */
//    @RequiresPermissions("mall:goodsTypeParams:add")
    @Log(title = "类型参数名称", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsTypeParams goodsTypeParams)
    {
        return toAjax(goodsTypeParamsService.insertGoodsTypeParams(goodsTypeParams));
    }

    /**
     * 修改类型参数名称
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsTypeParams goodsTypeParams = goodsTypeParamsService.selectGoodsTypeParamsById(id);
        mmap.put("goodsTypeParams", goodsTypeParams);
        return prefix + "/edit";
    }

    /**
     * 修改保存类型参数名称
     */
//    @RequiresPermissions("mall:goodsTypeParams:edit")
    @Log(title = "类型参数名称", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsTypeParams goodsTypeParams)
    {
        return toAjax(goodsTypeParamsService.updateGoodsTypeParams(goodsTypeParams));
    }

    /**
     * 删除类型参数名称
     */
//    @RequiresPermissions("mall:goodsTypeParams:remove")
    @Log(title = "类型参数名称", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(goodsTypeParamsService.deleteGoodsTypeParamsByIds(ids));
    }
}
